package com.xmg.day07;

/**
 * @Author: mazhongqing
 * @Date: 2020/10/29 11:10
 */
public class CacheLineDemo2 {
    static class M{
        public volatile long m;
    }

    public static M[] arr = new M[2];

    static {
        arr[0] = new M();
        arr[1] = new M();
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (long i = 0; i < 1000_0000; i++) {
                arr[0].m = i;
            }
        });

        Thread t2 = new Thread(()->{
            for (long i = 0; i < 1000_0000; i++) {
                arr[1].m = i;
            }
        });
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(System.currentTimeMillis()-start);
    }
}
